package lxt.dao.impl;

import java.util.ArrayList;
import java.util.List;

import lxt.dao.ParameterDao;
import lxt.entity.Parameter;
/**
 * 基础数据表管理dao
 * @author Lit
 *
 */
public class ParameterDaoImpl extends ABseDaoImpl implements ParameterDao {
	/**
	 * 根据paramType 查询信息
	 */
	@SuppressWarnings("unchecked")
	public List<Parameter> loadByParamType(String paramType){
		StringBuffer hql = new StringBuffer("Select p from Parameter p where 1=1 ");
		ArrayList<Object> param = new ArrayList<Object>();
		
		if(paramType!=null&&!paramType.equals("")){
			hql.append(" And p.id.paramType = ? ");
			param.add(paramType);
		}
		
		List<Parameter> parameters = this.getHibernateTemplate().find(hql.toString(), param.toArray());
		return parameters;
	}

	@SuppressWarnings("unchecked")
	public List<Parameter> loadAllParameter(String paramType, int offset,
			int length) {
		//查询的hql
		StringBuffer hql = new StringBuffer("select p from Parameter p where 1=1 ");
		//存入字段
		ArrayList<Object> param = new ArrayList<Object>();
		
		if(paramType!=null && !paramType.equals("")){
			hql.append(" And p.id.paramType like ?");
			param.add("%"+paramType+"%");
		}
		
		List<Parameter> parameters = (List<Parameter>) this.queryForPage(hql.toString(),param, offset, length);
		
		return parameters;
	}

	public int loadAllParameterCount(String paramType) {
		//查询的hql
		StringBuffer hql = new StringBuffer("select p from Parameter p where 1=1 ");
		//存入字段
		ArrayList<Object> param = new ArrayList<Object>();
		
		if(paramType!=null && !paramType.equals("")){
			hql.append(" And p.id.paramType like ?");
			param.add("%"+paramType+"%");
		}
		
		return this.getAllRowCount(hql.toString(), param);
	}
}
